/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.sigu.modelo.daoImpl;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TemporalType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import pe.edu.upc.sigu.entities.Periodos;
import pe.edu.upc.sigu.modelo.dao.PeriodoDao;

/**
 *
 * @author Usuario2
 */
@Repository(value="periodoDao")
public class PeriodoDaoImpl implements PeriodoDao {

    private  EntityManager entityManager =null;

    @PersistenceContext
    public void setEntityManager(EntityManager entityManager){
        this.entityManager = entityManager;
    }


    @Override
    public List<Periodos> getPeriodosList() {
        String sql = "SELECT p FROM Periodos p";
        Query query = entityManager.createQuery(sql);
        return query.getResultList();
    }

    @Override
    public Periodos getPeriodoDefault() {
       String sql = "SELECT * FROM sigu.aca_periodos p "
               + " WHERE  p.activo = B'1'";
        Query query = entityManager.createNativeQuery(sql, Periodos.class);
       // query.setParameter("activo", "B'10'");
        List resultList  = query.getResultList();
        if (resultList.size()>0){
            Periodos periodo = (Periodos) resultList.get(0);
            return periodo;
        }
        return null;
    }


}
